//
//  KEDownload.h
//  Karaoke
//
//  Created by Ka Leung Ke on 11-10-16.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
@protocol KEDownloadDelegate;

@interface KEDownload : NSObject
{
    NSURLRequest          * DownloadRequest;
    NSURLConnection       * DownloadConnection;
    NSMutableData         * receivedData;
    NSString              * localFilename;
    id <KEDownloadDelegate> delegate;
    long long               bytesReceived;
    long long               expectedBytes;

    float percentComplete;
}

- (KEDownload *) initWithURL:(NSURL *)fileURL timeout:(NSInteger)timeout delegate:(id <KEDownloadDelegate>)theDelegate;

@property (nonatomic, readonly) NSMutableData           * receivedData;
@property (nonatomic, readonly, retain) NSURLRequest    * DownloadRequest;
@property (nonatomic, readonly, retain) NSURLConnection * DownloadConnection;
@property (nonatomic, retain) NSString                  * localFilename;
@property (nonatomic, assign) id <KEDownloadDelegate>     delegate;

@property (nonatomic, readonly) float percentComplete;

@end

@protocol KEDownloadDelegate <NSObject>

@optional
- (void) downloadBar:(KEDownload *)downloadBar didFinishWithData:(NSData *)fileData suggestedFilename:(NSString *)filename;
- (void) downloadBar:(KEDownload *)downloadBar didFailWithError:(NSError *)error;
- (void) downloadBarUpdated:(KEDownload *)downloadBar;

@end